package ru.ifmo.tanya.service.mock;

import ru.ifmo.tanya.core.calls.CallManager;
import ru.ifmo.tanya.db.HuntGroupManager;
import ru.ifmo.tanya.service.HttpService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;


public class CreateCallService implements HttpService {

    private final CallManager callManager = new CallManager();
    private final HuntGroupManager huntGroupManager = new HuntGroupManager();

    @Override
    public void invoke(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String caller = request.getParameter("caller");
        int huntGroupId = Integer.parseInt(request.getParameter("hunt-group-id"));
        int id = callManager.addCall(caller, new Date(), huntGroupManager.getHuntGroupById(huntGroupId));
        PrintWriter out = new PrintWriter(response.getOutputStream());
        out.println("" + id);
        out.close();
    }
}
